#include <QyTexturePool.h>
#include "QpwRender.h"

QpwRender::QpwRender() {

    layers[QpwSubType::None].setZ(0);
    layers[QpwSubType::Player].setZ(0.1);
    layers[QpwSubType::Wall].setZ(0.12);
    layers[QpwSubType::Bush].setZ(0.125);
    layers[QpwSubType::Tree].setZ(0.13);

    addLayer(&layers[QpwSubType::None]);
    addLayer(&layers[QpwSubType::Player]);
    addLayer(&layers[QpwSubType::Wall]);
    addLayer(&layers[QpwSubType::Tree]);
    addLayer(&layers[QpwSubType::Bush]);

}

QpwRender::~QpwRender() {
}

bool QpwRender::loadData( const QString & dataPath ) {

    bool ok = true;

    ok = ok && styleDatabase.load( dataPath + "/styles.xml" );
    QyTexturePool::staticPool()->basePath = dataPath;

    return ok;
}

void QpwRender::initialize() {

    QyDbgLocation();
    glClearColor( 1, 1, 1, 1 );
    glPolygonOffset( 1.0, 2.0 );
    glPointSize(1);
    glLineWidth(1);
    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
    glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
    glEnable(GL_ALPHA_TEST);
    glEnable(GL_BLEND);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_POLYGON_OFFSET_FILL);
    glEnable(GL_TEXTURE_2D);

    QyTexturePool::staticPool()->loadFrom("");

}

void QpwRender::paint() {

//     glEnable(GL_ALPHA_TEST);
//     glEnable(GL_BLEND);
//     glEnable(GL_DEPTH_TEST);
//     glEnable(GL_POLYGON_OFFSET_FILL);
    glEnable(GL_TEXTURE_2D);
    QyRender::Painter::paint();

//     glDisable(GL_ALPHA_TEST);
//     glDisable(GL_BLEND);
//     glDisable(GL_DEPTH_TEST);
//     glDisable(GL_POLYGON_OFFSET_FILL);
    glDisable(GL_TEXTURE_2D);

}
